package featuremodel.constraint;

import java.util.Vector;

import featuremodel.FeatureGroup;
import featuremodel.FeatureModelDef;
import featuremodel.method.MRequireCompositeMethodBind;
import featuremodel.method.MRequireCompositeMethodUnBind;

import skyblue.Method;
import skyblue.Strength;

public class MRequireCompositeConstraint extends CompositeConstraint {

	private Vector<Method> methods1;
	private Vector<Method> methods2;

	public MRequireCompositeConstraint(FeatureGroup featureGroup1,
			String g1Type,FeatureGroup featureGroup2, String g2Type, 
			Strength strength) {
		
		super(strength);
		
		this.constraintType = FeatureModelDef.MREQUIRE_COMPLEX_CONSTRAINT;
		
		getVariables().addAll(featureGroup1.getVariables());
		getVariables().addAll(featureGroup2.getVariables());

		// Method1
		setGroupPredicTrue(featureGroup1, g1Type);
		methods1 = getTempMethods();
		setGroupPredicTrue(featureGroup2, g2Type);
		methods2 = getTempMethods();
		for (int i = 0; i < methods1.size(); i++) {
			for (int j = 0; j < methods2.size(); j++) {
				getMethods().add(
						new MRequireCompositeMethodBind(methods1.get(i),
								methods2.get(j)));

			}
		}
		
		
		if(methods1!=null){
			methods1.clear();
		}

		if(methods2!=null){
			methods2.clear();
		}

		// Method2
		setGroupPredicFalse(featureGroup1, g1Type);
		methods1 = getTempMethods();
		setGroupPredicFalse(featureGroup2, g2Type);
		methods2 = getTempMethods();
		for (int i = 0; i < methods1.size(); i++) {
			for (int j = 0; j < methods2.size(); j++) {
				getMethods().add(
						new MRequireCompositeMethodUnBind(methods1.get(i),
								methods2.get(j)));

			}
		}

	}
}
